package com.vhly.ddxdecompiler.dexreader.file.mixeditem;

import com.vhly.ddxdecompiler.dexreader.file.DexFile;
import com.vhly.ddxdecompiler.dexreader.io.DexInputStream;

import java.io.ByteArrayInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Vector;

/**
 * Created by IntelliJ IDEA.
 * User: vhly
 * Date: 2009-10-19
 * Time: 18:16:57
 *
 * @author vhly[FR]
 */
public class EncodedArrayItem extends Item {

    private Vector items;

    private DexFile dex;

    public EncodedArrayItem(DexFile dexFile) {
        dex = dexFile;
        items = new Vector();
    }

    /**
     * 读取数据
     *
     * @param din 输入流
     * @throws java.io.IOException 异常
     */
    public void read(DexInputStream din) throws IOException {
        ValueDecoder decoder = new ValueDecoder();
        Object[] objs = decoder.readArray(din);
        if (objs != null) {
            int size = objs.length;
            for (int i = 0; i < size; i++) {
                items.add(objs[i]);
            }
        }
    }

    /**
     * 输出数据
     *
     * @param dout 输出流
     * @throws java.io.IOException 异常
     */
    public void write(DataOutputStream dout) throws IOException {
    }

    public void reloc(ByteArrayInputStream bin, int offset) {

    }

    public int size(){
        return items.size();
    }

    public Object elementAt(int index){
        Object ret = null;
        if(index > -1 && index < items.size()){
            ret = items.elementAt(index);
        }
        return ret;
    }
}
